<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/10/13
 * Time: 17:06
 */
namespace common\components\widgets;

use yii\widgets\InputWidget;
use yii\helpers\Html;
class ChoiceIcon extends InputWidget{

    public $Icons=[
        'icon-money','icon-comment',
        'icon-user','icon-product',
        'icon-order','icon-useintegral',
        'icon-course','icon-member',
        'icon-card','icon-integral',
        'icon-pta','icon-system',
        'icon-match',
    ];

    public function init(){
        parent::init();

    }
    public  function run(){
        $strHtml='';
        if($this->hasModel()){
            $strHtml.=Html::activeHiddenInput($this->model,$this->attribute,['id'=>'input-menu-submit']);
        }
        else{
            $strHtml.=Html::hiddenInput($this->name,$this->value,['id'=>'input-menu-submit']);
        }
        $strHtml.=Html::beginTag('div');
        $strHtml.= Html::tag('span','',['class'=>'icon-card','id'=>'span-menu-attr','style'=>'margin:10px;']);
        $strHtml.=Html::tag('a',"&nbsp;&nbsp;&nbsp;更&nbsp;换&nbsp;图&nbsp;标&nbsp;&nbsp;&nbsp;",['id'=>'btn-menu-toggle','style'=>'position: absolute;background:#ccf;border-radius:10px;border:2px solid #ccc;']);
        $strHtml.=Html::endTag('div');
        $strHtml.= Html::beginTag('div',['id'=>'div-menu-toggle','style'=>'display:none;width: 200px;height: 150px;float: right;position: absolute; left:270px;top:130px;background:#6cf;padding-top:15px;overflow:auto;border-radius:15px;'])."\n";
        foreach($this->Icons as $v){
            if($v % 4 ==0){
                $strHtml.= "\n";
            }
            $strHtml.= Html::tag('span',"",['class'=>"{$v}",'style'=>'margin:10px;cursor:pointer ;']);
        }
        $strHtml.=Html::tag('a',"&nbsp;&nbsp;&nbsp;确&nbsp;定&nbsp;&nbsp;&nbsp;",['id'=>'btn-menu-click','style'=>'position: absolute;right:15px;bottom:10px;background:#6c3;border-radius:10px;border:2px solid #666;']);
        $strHtml.=Html::endTag('div');
        echo $strHtml;
        $this->showIcon();
    }
    public function showIcon(){
        $view=$this->getView();
        $js=<<<JS
            $('#span-menu-attr').attr('class',$('#input-menu-submit').val());
                $('#btn-menu-toggle').click(function(){
                    $('#div-menu-toggle').fadeToggle(500).show();
                    $('#btn-menu-click').click(function(){
                        $('#div-menu-toggle').hide();
                    });
                    $('span').click(function(){
                        var str = $(this).attr('class');
                        $('#span-menu-attr').attr('class',str);
                        $('#input-menu-submit').val(str);
                    })
                })
JS;
        $view->registerJs($js);
    }


}
